<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-color.css">
		<link rel="stylesheet" href="css/ui-res.css">
		<link rel="stylesheet" href="css/ui-img.css">
		<link rel="stylesheet" href="css/post.css">
        <script src="js/zy_control.js">
        </script>
        <script src="js/zy_click.js">
        </script>
        <script src="js/jquery-2.0.0.js">
        </script>
    </head>
    <body class="um-vp c-wh" ontouchstart>
        <div id="page_0" class="up ub ub-ver" tabindex="0">
            <!--header开始-->
            <div id="header" class="uh  t-wh ub" style="background-color:#222a38;">
	        	<div class="umw4 ver-txc2 " ontouchstart="zy_touch()" onclick="windowBack()">
	            <!--插入按钮控件--><img  class=" mar-l5 max-w1 max-h1" src="css/img/arrow2.png">
	        	</div>
	            <h1 class="ut ub-f1 ulev1 ut-s tx-c">头像上传</h1>
				<div class="umw4 ub ub-ver" ontouchstart="zy_touch()" onclick="">
					<div class="ub-f1 "></div>
					<div class="ub-f4">
						<div id="postBtn" onclick="uploadHeadPic()" class="ver-c ulev Public uc-a1" style="position:absolute;width:90%;height:100%;line-height:2em;vertical-align:middle;">保存</div>
					</div>
					<div class="ub-f1 "></div>
	            <!--插入按钮控件-->
	        	</div>
       		</div>
            <!--header结束--><!--content开始-->
            <div id="content" class="ub-f1 tx-c t-bla">
                	<div class="ub min-h13 ub-ver tx-c">
                		<div class="ub-f1" onclick="imgSelect(this)"><img id="img" src="css/img/defaultHead.jpg" style="max-width:10em;min-width:10em;"></div>
                		
					</div>
            </div>
            <!--content结束--><!--footer开始-->
            <div id="footer" class="uf c-m2 c-bla t-wh">
              
            </div>
            <!--footer结束-->
        </div>
    </body>
    <script>
    	zy_init();
		function windowBack(){
			uexWindow.windowBack();
		}
		
		function uploadHeadPic(){
			var uploadHttp = 'http://www.diaoyumi.ourstu.com/api/profile/uploadAvatar?session_id='+window.localStorage["session_id"];
			uexUploaderMgr.createUploader(1,uploadHttp);
		}
		function imgSelect(obj){
			uexWindow.cbConfirm=function(opId,dataType,data) {
			if(data==0){
				uexImageBrowser.pick();
			}
			else{
				cameraOpen();
			}
		}
		uexWindow.confirm("选择","",["相册","相机"]);
		}
		
		var upload_image_url='';
		window.uexOnload = function(){
//		uexFileMgr.cbExplorer=function(opCode,dataType,data){
//			upload_image_url = data;
//			document.getElementById("showPic").src = data;
//			document.getElementById("selectPic").style.display = "block";
//			document.getElementById("uploadPic").style.display = "block";
//			document.getElementById("divPic").style.display = "none";
//		}
		
		uexCamera.cbOpen = function(opCode, dataType, data){
			upload_image_url = data;
			var img=$('#img');
			img.attr("src",upload_image_url);
			
		}
		uexWidgetOne.cbError = function(opCode, errorCode, errorInfo){
			setLog(errorInfo);
		}
		
		uexImageBrowser.cbPick=function (opCode,dataType,data){
　　　　　　　 if(dataType==0){
				upload_image_url = data;
　　　　　　　 	var img=$('#img');
				img.attr("src",upload_image_url);
　　　　　　　 }
　　 	}
		uexUploaderMgr.cbCreateUploader =function(opCode,dataType,data){
			if(data == 0){	
			//	alert("创建成功");
			//	alert(document.getElementById('showPic').src);
			alert(upload_image_url);
				uexUploaderMgr.uploadFile(1,upload_image_url,"avatar",4);	
				uexWindow.toast(1,5,"头像上传ing...",0);
			}else{
				alert("创建失败");
			}
			
		}
		uexUploaderMgr.onStatus = function(opCode,fileSize,percent,serverPath,status){
			
			switch (status) {
					case 0:
						//setLog("上传进度："+percent+"%");
						break;
					case 1:
						//setLog(serverPath);
						//uexWindow.closeToast();//关闭提示消息框
						
						//alert(serverPath);
						var start=serverPath.indexOf("{",0);
						var end=serverPath.indexOf("}",0);
						var json=serverPath.substring(start,(end+1));
						//alert(json);
						json=eval("("+json+")");
						//alert(json["success"]);
						if(json["success"]){
							uexWindow.toast(0,5,"设置成功~",1000);
							uexWindow.windowBack();
						}else{
							uexWindow.toast(0,5,json["message"],1000);
						}
						//uexWindow.closeToast();//关闭提示消息框
						uexUploaderMgr.closeUploader(1);
						break;
					case 2:
						//setLog("上传出错");
						uexWindow.closeToast();//关闭提示消息框
						uexWindow.toast(0,5,"出错啦~",2000);
						//uexWindow.closeToast();//关闭提示消息框
						uexUploaderMgr.closeUploader(1);
						break;

			}
			
		}
	}
    </script>
</html>
